from Base.basePage import BasePage
from selenium.webdriver.common.by import By

class RegisterPage(BasePage):
    username=(By.NAME,"accounts")
    password=(By.NAME,"pwd")

    registerBtn=(By.XPATH,"/html/body/div[1]/div[1]/div[3]/div/div/div[2]/div/div[1]/div[1]/form/div[5]/button")  #注册按钮
    checkAgreement=(By.XPATH,"/html/body/div[1]/div[1]/div[3]/div/div/div[2]/div/div[1]/div[1]/form/div[4]/label")  #勾选协议

    def __init__(self,driver):
        super().__init__(driver)
        self.driver=driver
        self.url="https://d2.shopxo.vip/regster.html"


    def open(self):
        """打开注册页面"""
        self.driver.get(self.url)
        self.wait_for_element(self.registerBtn)
        return self
    def is_on_register_page(self):
        """检查是否在注册界面"""
        return "用户注册" in self.driver.title
    def input_username(self,username):
        """输入用户名"""
        self.input_text(self.username,username)
        return self
    def input_password(self,password):
        """输入密码"""
        self.input_text(self.password,password)
        return self
    def click_register_btn(self):
        """点击注册按钮"""
        self.click_element(self.registerBtn)
        return self
    def click_check_agreement(self):
        """勾选协议"""
        self.click_element(self.checkAgreement)
        return self
    def register(self,username,password):
        self.open()
        self.input_username(username)
        self.input_password(password)
        self.click_check_agreement()
        self.click_register_btn()

        return self
    def is_register_successful(self):
        """检查是否注册成功"""
        if "联系我们-果博东方有限公司开户电话18108888862（客服）" in self.driver.title:
            return True
        else:
            return False



